<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-tag type="success">筛选：</el-tag>
            <el-date-picker v-model="searchinfo.times" type="daterange" align="right" placeholder="选择日期范围" :picker-options="pickerOptions2" @change="getList">
            </el-date-picker>
            <el-select v-model="searchinfo.ordertype" @change="getList" class="w200">
                <el-option :key="0" label="请选择单据类型" :value="0"></el-option>
                <el-option :key="10" label="退卡" :value="10"></el-option>
                <el-option :key="11" label="退款" :value="11"></el-option>
            </el-select>
            <el-select v-model="searchinfo.status" @change="getList" class="w200">
                <el-option label="请选择状态" :value="0"></el-option>
                <el-option label="未分配" :value="1"></el-option>
                <el-option label="已分配" :value="2"></el-option>
            </el-select>
            <el-button type="primary" @click="getList" style="float: right; margin-left: 5px" icon="h-shuaxin1">刷新列表</el-button>
            <el-input style="width: 20%; float: right" placeholder="搜索顾客姓名" v-model="searchinfo.search" @keyup.enter.native="getList">
                <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
            </el-input>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <!-- <el-table-column prop="id" label="ID" width="80"></el-table-column> -->
            <el-table-column prop="order_sn" label="单号" width="170"></el-table-column>
            <el-table-column prop="name" label="顾客姓名">
                <template slot-scope="scope">
                    <span @click="openGuestPage(scope.row.guestid)" style="cursor:pointer;color:#f50">{{scope.row.name}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="ordertype" label="出入类型">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.ordertype" typeName="orderType"></Tags>
                </template>
            </el-table-column>
            <el-table-column prop="money" label="退还业绩"></el-table-column>
            <el-table-column prop="addtime" label="开单日期" show-overflow-tooltip>
                <template slot-scope="scope">
                    {{scope.row.addtime|hourTime}}
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-tooltip content="分配工资" placement="left" :open-delay="800" v-if="scope.row.status == 1" v-qx="quanxian.allot">
                        <el-button icon="el-icon-h-bumen" type="warning" size="mini" @click="fenpei(scope.row)"></el-button>
                    </el-tooltip>
                    <el-tooltip content="查看分配" placement="left" :open-delay="800" v-else v-qx="quanxian.look">
                        <el-button type="primary" icon="el-icon-h-chakan" size="mini" @click="chakan(scope.row)"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :page-sizes="[15, 30, 50, 100]" :page-size="searchinfo.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
import Guest from '#/src/shop/guest.js'
import Tags from '@/components/orderTags.vue'

export default {
    name: 'backCheckList',
    data() {
        return {
            list: [],
            total: 0,
            searchinfo: {
                currentPage: 1,
                pageSize: 15,
                search: '',
                ordertype: 0,
                status: 0,
                times: [new Date(), new Date()],
            },
            quanxian: {
                allot: 'kouchu_allot',
                look: 'kouchu_look',
            },
            pickerOptions2: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date()
                        const start = new Date()
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
                        picker.$emit('pick', [start, end])
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date()
                        const start = new Date()
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
                        picker.$emit('pick', [start, end])
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date()
                        const start = new Date()
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
                        picker.$emit('pick', [start, end])
                    }
                }]
            }
        }
    },
    methods: {
        fenpei: async function(row) {
            let res = await C.openBrowserWindow('/checkBackCard', { id: row.id, type: row.ordertype, gid: row.gid }, { width: 1400, height: 880, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
            if (res) C.success(res.data)
            this.getList()
        },

        chakan: async function(row) {
            let res = await C.openBrowserWindow('/backCardInfo', { id: row.id }, { width: 1400, height: 880, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
            if (res) C.success(res.data)
            this.getList()
        },

        sizeChange: function(val) {
            this.searchinfo.pageSize = val
            this.getList()
        },

        currentChange: function(val) {
            this.searchinfo.currentPage = val
            this.getList()
        },

        getList: async function() {
            let url = '/shop/kaidancheck/tuidanlist'
            let data = { searchinfo: JSON.stringify(this.searchinfo) }
            let res = await C.ajax(url, data, 'post')
            if (res) {
                this.list = res.data
                this.total = res.count
            }
        },
        openGuestPage(id) {
            Guest.openGuestPage(id)
        }
    },
    mounted: function() {
        this.getList()
    },
    components: { Tags }
}
</script>